<template>
  <div class="app-container1">
    <el-table v-loading="loading" :data="tastList">
      <el-table-column label="序号" align="center" type="index"/>
      <el-table-column label="流程名称" align="center" prop="instanceName"/>
      <el-table-column label="订单编号" align="center" prop="name"/>
      <el-table-column label="任务状态" align="center" prop="status"/>
      <el-table-column label="办理人" align="center" prop="assignee"/>
      <el-table-column label="创建时间" align="center" prop="createdDate"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="taskProgress (scope.row)"
          >任务进度
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleCheck(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      :visible.sync="modelVisible"
      title="进度查询"
      width="1680px"
      append-to-body
    >
      <div style="position:relative;height: 100%;">
        <iframe
          id="iframe"
          :src="modelerUrl"
          frameborder="0"
          width="100%"
          height="720px"
          scrolling="auto"
        ></iframe>
      </div>
    </el-dialog>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

import {getHistoryInfo} from "@/api/activiti/task";
import operationalForm from "@/views/activiti/businessComponent/operationalForm";
import {getAttendanceStatistics} from "@/api/job/attendance/attendanceApi";
import {getOperationalInfo2} from "@/api/operation";
import {getDefinitionsByInstanceId} from '@/api/activiti/definition'
import {dateFormatter} from "@/api/tool/DateUtil";

export default {
  name: "myInitiator",
  components: {operationalForm},
  data() {
    return {
      modelVisible: false,
      modelerUrl: '',
      id:'',
      definitionKey: '',
      businessKey: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假表格数据
      tastList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        formData:[]
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询请假列表 */
    getList() {
      this.loading = true;
      getHistoryInfo(this.queryParams).then(response => {
        this.tastList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.definitionKey = '',
        this.businessKey = '',
        this.form = {
          formData:[],
        };
      this.resetForm("form");
    },

    /**任务进度**/
    taskProgress(row){

      getDefinitionsByInstanceId(row.id).then(response => {
        let data = response.data
        this.modelerUrl = '/bpmnjs/index.html?type=lookBpmn&instanceId=' + row.id + '&deploymentFileUUID=' + data.deploymentID + '&deploymentName=' + encodeURI(data.resourceName);
        this.modelVisible = true
      })
    },
    /** 详情按钮操作 */
    handleCheck(row){
      const id = row.businessKey.split('_')[1];
      let name =row.businessKey.split('_')[0]
      if(name=='yyxq'){
        getOperationalInfo2(id).then(res=>{
          const status =res.data.status;
          const params = { id: id,status:status, handleType: 'view'};
          this.$router.push({ path:"/plan/employeeDetail", query: params });
        })
      }else if(name=='lsgkq'){
        getAttendanceStatistics(id).then(response => {
          let orderCode =response.data.orderCode;
          let workTime =response.data.workTime;
          workTime=dateFormatter(workTime);
          this.$router.push({path:"/personnel/attendance/attendanceGroupDetail",query:{workTime:workTime,orderCode:orderCode}});
        });

      }
    },
  }
};
</script>
